package com.polaris.live.utils.photo

import android.app.Activity
import android.content.Intent
import android.view.View
import com.blankj.utilcode.util.ScreenUtils
import com.polaris.live.resp.back_resp.InfoOtherResp


/**
 * PicturePreview
 * @author Created by 天晴 on 2024/1/11 10:44
 * @since 1.0.0
 **/
class PicturePreview(val activity: Activity) {

    private var left = ScreenUtils.getScreenWidth() / 2
    private var top = ScreenUtils.getScreenHeight()
    private var width = 0
    private var height = 0
    private var index: Int = 0
    private var user: InfoOtherResp? = null
    private var urls: ArrayList<String>? = null


    companion object {
        fun with(activity: Activity): PicturePreview {
            return PicturePreview(activity)
        }
    }

    fun byView(view: View): PicturePreview {
        val location = IntArray(2)
        view.getLocationOnScreen(location)
        left = location[0]
        top = location[1]
        width = view.width
        height = view.height
        return this
    }

    fun setImageUrlList(list: ArrayList<String>): PicturePreview {
        urls = list
        return this
    }

    fun setIndex(index: Int): PicturePreview {
        this.index = index
        return this
    }

    fun setUserInfo(user: InfoOtherResp?): PicturePreview {
        this.user = user
        return this
    }

    fun go() {
        val intent = Intent(activity, DragPhotoActivity::class.java)

        intent.putExtra("left", left)
        intent.putExtra("top", top)
        intent.putExtra("height", height)
        intent.putExtra("width", width)
        intent.putExtra("userInfo", user)
        urls?.let {
            intent.putStringArrayListExtra("list", it)
            if (index < 0 || index >= it.size) {
                index = 0
            }
            intent.putExtra("index", index)
            activity.startActivity(intent)
            activity.overridePendingTransition(0, 0)
        }


    }
}